#pragma once

#include "atlwince.h"
#include "MembersDb.h"

class CMembersDlg :
    public CStdDialogResizeImpl<CMembersDlg>
{
public:
    CMembersDlg(UINT GroupId, CString GroupName);

    enum { IDD = IDD_MEMBERS };

    BEGIN_DLGRESIZE_MAP(CMembersDlg)
        DLGRESIZE_CONTROL(IDC_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y)
    END_DLGRESIZE_MAP()

    BEGIN_MSG_MAP(CMembersDlg)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
        MESSAGE_HANDLER(WM_SIZE, OnSize)
        NOTIFY_HANDLER(IDC_LIST, NM_CLICK, OnListClick)
        NOTIFY_HANDLER(IDC_LIST, NM_RETURN, OnListReturn)
        COMMAND_ID_HANDLER(ID_MENU_CONTACTS, OnMenuContacts)
        COMMAND_ID_HANDLER(ID_MENU_DELETE, OnMenuDelete)
        COMMAND_ID_HANDLER(ID_MENU_CANCEL, OnMenuCancel)
        COMMAND_ID_HANDLER(ID_MENU_ADD_FROM_GROUP, OnMenuAddFromGroup)
        COMMAND_ID_HANDLER(ID_MENU_CLEAR, OnMenuClear)
        CHAIN_MSG_MAP(CStdDialogResizeImpl<CMembersDlg>)
    END_MSG_MAP()

private:

    // Handler prototypes (uncomment arguments if needed):
    //	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    //	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
    //	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

    LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled);
    LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled);
    LRESULT OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled);

    LRESULT OnListClick(int idCtrl, LPNMHDR pnmh, BOOL& /*bHandled*/);
    LRESULT OnListReturn(int idCtrl, LPNMHDR pnmh, BOOL& /*bHandled*/);

    LRESULT OnMenuContacts(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnMenuDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnMenuCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnMenuAddFromGroup(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnMenuClear(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

    void OnSize(void);
    void PopulateList(void);
    void AddNewMember(void);
    void AddMember(UINT MemberId, CString &Name, CString &Number);
    void EditMember(int ListIndex, UINT MemberId);
    CString GetDisplayText(CString &Name, CString&Number);

    void OnItem(int ItemId);

    CImageList m_ImageList;
    CListViewCtrl m_List;
    CString m_GroupName;
    CMembersDb m_MembersDb;
    UINT m_GroupId;
    bool m_DisplayNumber;
};
